package com.example.steveaoblogdemo.controller;

import com.example.steveaoblogdemo.service.impl.FriendServiceImpl;
import com.example.steveaoblogdemo.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class FriendController {
    @Resource
    FriendServiceImpl friendService;

    @GetMapping("/friend/query")
    public Result<?> query(){
        return friendService.queryFriend();
    }

    @GetMapping("/friend/queryFriend")
    public Result<?> queryFriend(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize,@RequestParam(defaultValue = "") String search){
        return friendService.queryFriend(pageNum,pageSize,search);
    }

    @PostMapping("/friend/addFriend")
    public int addFriend(@RequestParam(required = false) Integer id,@RequestParam(defaultValue = "")String fName,@RequestParam(defaultValue = "")String fLink){
        return friendService.addFriend(id,fName,fLink);
    }

    @PutMapping("/friend/updateFriend")
    public int updateFriend(@RequestParam(defaultValue = "")String fName,@RequestParam(defaultValue = "")String fLink,@RequestParam(required = false)Integer id){
        return friendService.updateFriend(fName,fLink,id);
    }

    @PutMapping("/friend/deleteFriend")
    public Result<?> deleteFriend(@RequestParam(required = false)Integer id){
        return friendService.deleteFriend(id);
    }

    @GetMapping("/friend/queryById")
    public Result<?> queryById(@RequestParam(required = false) Integer id){
        return friendService.queryById(id);
    }
}
